package com.atguigu.Partition;

import com.atguigu.Bean.OrderBean;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class GroupComparator extends WritableComparator {

    //重写无参构造方法，定义反射出来的对象是OrderBean类
    public GroupComparator() {
        super(OrderBean.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        OrderBean first = (OrderBean) a;
        OrderBean second = (OrderBean) b;
        //比较orderId，如果相同就认为是同一组数据
        return first.getOrderId().compareTo(second.getOrderId());
    }
}
